<template>
	<view>
		<notices :messages="messages" :handleNoticeInfo="handleNoticeInfo">
		</notices>
		<!-- <tui-loadmore v-if="loading"></tui-loadmore> -->
		<tui-nomore v-if="!allowLoading"></tui-nomore> <!--显示没有更多数据-->
	</view>
</template>

<script>
import textMap from "@/utils/TextMap.js"
import c from "@/utils/Constant.js"
import noticeParser from "@/utils/NoticeParser.js"
import notices from "@/pages/message/notices.vue";
import messageApi from "@/request/api/messageApi.js";
import communityApi from "@/request/api/communityApi.js";
import listUtils from "@/utils/ListUtils.js"
import userUtils from "@/utils/userUtils.js"
import noticeBuilder from "@/utils/NoticeBuilder.js"
const commentUrl = "#/"  //评论详情的url
const topicUrl = "#/"	 //话题详情的url
	export default {
		data() {
			return {
				messages:[	
				],
				comments:[], //评论集合
				topics:[],    //话题集合
				page:{
					currentPage:1,
					size:10
				},
				allowLoading:true,//是否允许加载，如果数据已经全部拉取完毕，就可以关闭了
			}
		},
		created(){
			this.getFollowMessages();
			
		},
		methods: {
			//拉取消息关注我的消息
			getFollowMessages(){
				messageApi.historyListByType(c.action.FOLLOW,this.page).then((data)=>{
					if(data.code == 0){						
						let resultList = data.page.list
						this.messages = [...this.messages,...resultList]
						if(resultList.length < this.page.size){//如果查出来的记录数小于要求的记录数，说明已经没有记录拉取了
							this.allowLoading = false; //不允许继续拉取记录
						}
						this.page.currentPage++;
					}
				})
			},
			//处理通知的逻辑，由通知组件来调用
			handleNoticeInfo(message,trigger){
				//let msgCon = JSON.parse(message.content);
				return this.buildFollowNotice(message,trigger.nickname);
			},
			
			buildFollowNotice(message,triggerNickname){
				let notice = {title:'',content:'',entity:'',jumpUrl:''}
				//通过解析器获取消息对应的通知内容
				notice.title = noticeParser.parseTitle(message,triggerNickname);
				//构建通知对象
				return notice
			}
		},
		components:{
			notices
		},
		// 页面上拉触底事件的处理函数
		onReachBottom: function() {
			if(this.allowLoading){
				this.getFollowMessages()
			}
		}
	}
</script>


<style>
</style>
